class Solution {
    public:
        double myPow(double x, int n) {
            if(n < 0) return 1/dfs(x,-(long long) n);
            else return dfs(x,n);
        }
        double dfs(double x, long long n){
            if(n == 0)  return 1;
            double tmp = dfs(x,n/2);
            if(n%2 == 0) return tmp*tmp;
            else return tmp*tmp*x;
        }
    };